import Vue from 'vue'
import Vuex from 'vuex'
import tagsView from '@/store/modules/tagsView'
import navList from '@/store/modules/navList'
import { getCookie, setCookie, delCookie } from '../utils/cookie'
Vue.use(Vuex)

let token = getCookie('token')
let tokenType= getCookie('tokenType')
let isLogin = token ? true : false

export default new Vuex.Store({
  state: {
    token: token,
    tokenType: tokenType,
    isLogin: isLogin,
    isNavShrink: false
  },
  mutations: {
    LOGIN_IN(state, { token = '' ,tokenType=''}) {
      state.isLogin = true
      state.token = token
      state.tokenType = tokenType
      setCookie('token', token, 10)
      setCookie('tokenType', tokenType, 10)
      localStorage.token = token
    },

    LOGIN_OUT(state) {
      state.isLogin = false
      state.token = ''
      state.tokenType = ''
      delCookie('token')
      delCookie('tokenType')
      localStorage.token = ''
    },

    // 导航 展开/收缩
    SCROLL_NAV(state) {
      state.isNavShrink = !state.isNavShrink
    }
  },

  actions: {},

  getters: {
    visitedViews: state => state.tagsView.visitedViews,
    cachedViews: state => state.tagsView.cachedViews,
    navList: state => state.navList.list
  },

  modules: {
    tagsView,
    navList
  }
})
